package com.weiyuwqj.controller.account;

import com.weiyuwqj.api.service.BusAccountLogService;
import com.weiyuwqj.api.common.Paginator;
import com.weiyuwqj.api.util.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * Created by zhangyong on 2016/11/28.
 */
@Controller
public class AccountLogController {

    @Autowired
    BusAccountLogService accountLogService;

    /**
     * 个人资金记录页面
     * @return
     */
    @RequestMapping("/user/log")
    public Object log(){
        return "main/user/moneyRecord";
    }

    /**
     * 资金记录
     * @param request
     * @param p 分页
     * @param beginDateTime 开始时间
     * @param endDateTime 结束时间
     * @param type  类型：0-全部，1-一周，2-一个月，3-一季度
     * @return
     */
    @ResponseBody
    @RequestMapping("/user/account/logList")
    public Object bill(HttpServletRequest request,Paginator p,String beginDateTime,String endDateTime,Integer type,String operType){
        Integer userId = (Integer) request.getSession().getAttribute("userId");
        Map amountLogParam=new HashMap();
        amountLogParam.put("userId",userId);
        amountLogParam.put("remove",1);
        amountLogParam.put("type",operType);
        Date date = DateUtils.getNextDayStartTime(new Date());
        SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
        if(type==1){
            endDateTime = sdf.format(date);
            date=DateUtils.addTime(1,date,-7);
            beginDateTime=sdf.format(date);
        }else if(type==2){
            endDateTime = sdf.format(date);
            date=DateUtils.addTime(2,date,-1);
            beginDateTime=sdf.format(date);
        }else if(type==3) {
            endDateTime = sdf.format(date);
            date=DateUtils.addTime(3,date,-1);
            beginDateTime=sdf.format(date);
        }
        amountLogParam.put("beginDateTime", beginDateTime);
        amountLogParam.put("endDateTime",endDateTime);
        return accountLogService.getList(p, amountLogParam);
    }

    /**
     *
     */
    @ResponseBody
    @RequestMapping(value="/account/countAccountLog")
    public Object countAccountLog(HttpServletRequest request){
        Integer userId = (Integer) request.getSession().getAttribute("userId");
        //Map map=accountLogService.countAccountLog(userId);
        return null;
    }
}
